package com.deer.wms.inventory.model.Inventory;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.deer.wms.inventory.constant.InventoryConstant;
import com.deer.wms.inventory.model.InventoryAdjustDetailDto;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.*;

@Getter
@Setter
@NoArgsConstructor
@Table(name = "inventory_transact")
public class InventoryTransact {
    /**
     * 主键
     */
    @Id
    @TableId(type = IdType.AUTO)
    @Column(name = "inventory_transact_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer inventoryTransactId;

    /**
     * 事务类型
     */
    @Column(name = "transact_type")
    private Integer transactType;

    /**
     * ???
     */
    @Column(name = "bill_type")
    private Integer billType;

    /**
     * 关联的单据号
     */
    private String billNo;

    @Column(name = "detail_no")
    private String detailNo;

    private String reason;

    /**
     *
     */
    private Integer state;

    /**
     * 状态描述
     */
    private String stateDis;

    @Column(name = "create_user_id")
    private Integer createUserId;

    private String createUserName;

    @Column(name = "create_time")
    private String createTime;

    @Column(name = "item_code")
    private String itemCode;

    private String itemName;
    private String spec;
    private String model;
    private String imgUrl;

    @Column(name = "ware_id")
    private Integer wareId;

    private String wareName;
    private Integer fromInventoryId;

    @Column(name = "from_organization_id")
    private Integer fromOrganizationId;

    @Column(name = "from_organization_name")
    private String fromOrganizationName;

    @Column(name = "from_batch_id")
    private Integer fromBatchId;

    @Column(name = "from_batch_name")
    private String fromBatchName;

    @Column(name = "from_box_code")
    private String fromBoxCode;

    @Column(name = "from_cell_code")
    private String fromCellCode;

    @Column(name = "from_pack_describe")
    private String fromPackDescribe;

    @Column(name = "from_pack_detail_id")
    private Integer fromPackDetailId;

    @Column(name = "from_trans_ratio")
    private Double fromTransRatio;

    /**
     * 主单位数量
     */
    @Column(name = "from_quantity")
    private Double fromQuantity;

    @Column(name = "to_organization_id")
    private Integer toOrganizationId;
    private Integer toInventoryId;

    @Column(name = "to_organization_name")
    private String toOrganizationName;

    @Column(name = "to_batch_id")
    private Integer toBatchId;

    @Column(name = "to_batch_name")
    private String toBatchName;

    @Column(name = "to_box_code")
    private String toBoxCode;

    @Column(name = "to_cell_code")
    private String toCellCode;

    @Column(name = "to_pack_detail_id")
    private Integer toPackDetailId;

    @Column(name = "to_pack_describe")
    private String toPackDescribe;

    @Column(name = "to_trans_ratio")
    private Double toTransRatio;

    @Column(name = "to_quantity")
    private Double toQuantity;


    @Column(name = "to_ware_id")
    private Integer toWareId;

    @Column(name = "to_ware_name")
    private String toWareName;

//    private Integer relateId;
//
//    private Integer asnStockId;
//    private String asnStockName;

    public InventoryTransact(Integer transactType, Integer billType, String detailNo, String reason, Integer state, Integer createUserId, String createUserName, String createTime, String itemCode, String itemName, Integer wareId, String wareName,  Double fromQuantity, Integer toOrganizationId, String toOrganizationName, Integer toBatchId, String toBatchName, String toBoxCode, String toCellCode, Integer toPackDetailId, String toPackDescribe, Double toQuantity, Integer toWareId, String toWareName,Integer fromInventoryId) {
        this.transactType = transactType;
        this.billType = billType;
        this.detailNo = detailNo;
        this.reason = reason;
        this.state = state;
        this.createUserId = createUserId;
        this.createUserName = createUserName;
        this.createTime = createTime;
        this.itemCode = itemCode;
        this.itemName = itemName;
        this.wareId = wareId;
        this.wareName = wareName;
        this.fromInventoryId = fromInventoryId;

        this.fromQuantity = fromQuantity;
        this.toOrganizationId = toOrganizationId;
        this.toOrganizationName = toOrganizationName;
        this.toBatchId = toBatchId;
        this.toBatchName = toBatchName;
        this.toBoxCode = toBoxCode;
        this.toCellCode = toCellCode;
        this.toPackDetailId = toPackDetailId;
        this.toPackDescribe = toPackDescribe;
        this.toQuantity = toQuantity;
        this.toWareId = toWareId;
        this.toWareName = toWareName;
    }

    public InventoryTransact(InventoryAdjustDetailDto inventoryAdjustDetailDto) {
        this.transactType = InventoryConstant.INVENTORY_ADJUST;
        this.detailNo = inventoryAdjustDetailDto.getDetailNo();
        this.reason = inventoryAdjustDetailDto.getReason();
        this.state = 1;

        this.itemCode = inventoryAdjustDetailDto.getItemCode();
        this.itemName = inventoryAdjustDetailDto.getItemName();
        this.wareId = inventoryAdjustDetailDto.getWareId();
        this.wareName = inventoryAdjustDetailDto.getWareName();
        this.fromOrganizationId = inventoryAdjustDetailDto.getOrganizationId();
        this.fromOrganizationName = inventoryAdjustDetailDto.getOrganizationName();
        this.fromBatchId = inventoryAdjustDetailDto.getBatchId();
        this.fromBatchName = inventoryAdjustDetailDto.getBatchName();
        this.fromBoxCode = inventoryAdjustDetailDto.getBoxCode();
        this.fromCellCode = inventoryAdjustDetailDto.getCellCode();
        this.fromPackDescribe = inventoryAdjustDetailDto.getPackDescribe();
        this.fromPackDetailId = inventoryAdjustDetailDto.getPackDetailId();
        this.fromQuantity = inventoryAdjustDetailDto.getQuantity();
        this.toOrganizationId = inventoryAdjustDetailDto.getOrganizationId();
        this.toOrganizationName = inventoryAdjustDetailDto.getOrganizationName();
        this.toBatchId = inventoryAdjustDetailDto.getBatchId();
        this.toBatchName = inventoryAdjustDetailDto.getBatchName();
        this.toBoxCode = inventoryAdjustDetailDto.getBoxCode();
        this.toCellCode = inventoryAdjustDetailDto.getCellCode();
        this.toPackDetailId = inventoryAdjustDetailDto.getPackDetailId();
        this.toPackDescribe = inventoryAdjustDetailDto.getPackDescribe();
        this.toQuantity = inventoryAdjustDetailDto.getAdjustQuantity();
        this.toWareId = inventoryAdjustDetailDto.getWareId();
        this.toWareName = inventoryAdjustDetailDto.getWareName();
        this.fromTransRatio = inventoryAdjustDetailDto.getTransRatio();
        this.toTransRatio = inventoryAdjustDetailDto.getTransRatio();

        this.fromInventoryId = inventoryAdjustDetailDto.getInventoryId();
    }
}
